package com.leps.nq.tx.controller;

import com.leps.nq.common.aspect.Log;
import com.leps.nq.common.enums.BusinessType;
import com.leps.nq.common.vo.R;
import com.leps.nq.common.vo.RBuilder;
import com.leps.nq.tx.entity.PrivateCloudServer;
import com.leps.nq.tx.service.IPrivateCloudServerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 私有云服务器表 前端控制器
 * </p>
 *
 * @author hex
 * @since 2022-07-23
 */
@RestController
@RequestMapping("/private-cloud-server")
@Api(tags = "私有云服务器管理")
public class PrivateCloudServerController {
    @Autowired
    IPrivateCloudServerService service;

    @ApiOperation("私有云服务器列表")
    @GetMapping
    public R<List<PrivateCloudServer>> list() {
        return RBuilder.ok(service.list());
    }

    @ApiOperation("根据id查询私有云服务器")
    @GetMapping("/{id}")
    public R<PrivateCloudServer> getById(@PathVariable int id) {
        return RBuilder.ok(service.getById(id));
    }

    @ApiOperation("新增私有云服务器")
    @PostMapping
    @Log(title = "私有云服务器", businessType = BusinessType.INSERT)
    public R save(@RequestBody PrivateCloudServer entity) {
        service.save(entity);
        return RBuilder.ok();
    }

    @ApiOperation("修改私有云服务器")
    @PutMapping
    @Log(title = "私有云服务器", businessType = BusinessType.UPDATE)
    public R update(@RequestBody PrivateCloudServer entity) {
        service.updateById(entity);
        return RBuilder.ok();
    }

    @ApiOperation("删除私有云服务器")
    @DeleteMapping
    @Log(title = "私有云服务器", businessType = BusinessType.DELETE)
    public R remove(@RequestBody List<Integer> ids) {
        service.removeBatchByIds(ids);
        return RBuilder.ok();
    }
}
